package com.iwunu.gateway.util;

import javax.imageio.stream.FileImageOutputStream;
import java.io.File;
import java.util.Arrays;

/**
 * @author harvey
 * @date 2019/1/15 11:13 AM
 * @desc byte转image
 */
public class ByteToImageUtil {
    public static byte[] fromHexString(String s) {
        int length = s.length() / 2;
        byte[] bytes = new byte[length];
        for (int i = 0; i < length; i++) {
            bytes[i] = (byte) ((Character.digit(s.charAt(i * 2), 16) << 4) | Character
                    .digit(s.charAt((i * 2) + 1), 16));
        }
        return bytes;
    }
    public static void byte2image(byte[] data,String path){
        if(data.length<3||path.equals("")) return;
        try{
            FileImageOutputStream imageOutput = new FileImageOutputStream(new File(path));
            imageOutput.write(data, 0, data.length);
            imageOutput.close();
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(fromHexString("ffd8ffe000104a46494600010101000000000000ffdb0043000c08090b09080c0b0a0b0e0d0c0e121e1412111112251a1c161e2c262e2d2b262a293036453b30334134292a3c523d41474a4d4e4d2f3a555b544b5a454c4d4affdb0043010d0e0e121012231414234a322a324a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4a4affc4001f0000010501010101010100000000000000000102030405060708090a0bffc400b5100002010303020403050504040000017d01020300041105122131410613516107227114328191a1082342b1c11552d1f02433627282090a161718191a25262728292a3435363738393a434445464748494a535455565758595a636465666768696a737475767778797a838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae1e2e3e4e5e6e7e8e9eaf1f2f3f4f5f6f7f8f9faffc4001f0100030101010101010101010000000000000102030405060708090a0bffc400b51100020102040403040705040400010277000102031104052131061241510761711322328108144291a1b1c109233352f0156272d10a162434e125f11718191a262728292a35363738393a434445464748494a535455565758595a636465666768696a737475767778797a82838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae2e3e4e5e6e7e8e9eaf2f3f4f5f6f7f8f9faffc000110800f0014003012100021101031101ffda000c03010002110311003f00c64b301f71726ad5e2f9f6ea91fc8c0e73baa6fa9041f679d538932de99a818ea0a3e5047e4698c83edb7b002d347f2fa95ae7e73e648ee3f88934d00fb33d455f5ade04b1f4ead842d4571f72811227dd14eaa403b34ecd5087034ecd500e0d4b4c414a1a980ee1b9ef4f0cc3ef8cfbd202b5d6950dd0dd1feedfd7b561dcd9cd6a712a63dfb1ae6ab4faa348b2bd15cc68252500318532800fad21a9105140053850048829f40cebe2bdb740764d187eccfdaab7d8eec379b06a0d267aef240353a7520918ea11afcb893f1aaadaa5f43f34d6a368ff00648a2dd86490788206ff005b14887fd83baaa6ad2437b76b342fbf2b86ce7ad30b19710f2ee197deb49056f01325db462b62431514e3e4a603c74a75002d2d500ea5ab10ea5a621f4bd6980b8a914d3112aaff00778a790b2298e55041ec7a5401917da01e5ed0e7fe999ac3742ac558608ec6b96a46c6b163692b12c4a615a008cd14804a5a4214548a334012d140cd3f3613febadb6fd296286d19f7c53c913ff7a93117d1ee82fcb70253efd693fb5aeedce67b5e3d465695bb0127db34bbc399e30afeae9cd3d34eb4ff005b68dbbd407dc29ddf503175783ecfa806ed2283fd2ae5baee406b58089b6526dadc91b8a8a71f25500b8f9452d0805a5aa10b4b5402d3a9885a78aa01eb520140878a941f5a90241f2f4e45417ba75bea0bf3fcb27f7c75a9607337fa6cf62dfbd195ece3a1aa75c728d99b094950318cb9a888a004a05003c54e38a402d14016edefe68feeb03fef0abbf6884e0dcd8260ff001447147a0132436520cdb5e98cff00726152ac5a95baef45f313fbd11dd4b4115fceb691bf7f6ebbbd47152c1696a678e58a6c146ce1c668d7a8c4f11c398a297fbad8a5d27e7b7fa55c445b68ea2295d040c2b50ccbf25300c7ca2a398ec4cd3404514d93cd59a6b510b4eaa01696ac05a70a603c548b4089453c5210f538a9060f3de90c7305914a4ca083d8f435ceea9a13c1996d72f1f75ee2b392ba1ad0c5a4c5721a8da695cd2022229b4087d3d4d219252d00253d198743401287cf5ab8ab716a44b13b27fb4a68dc09ceab2bf1751c73fbbaf34ddf672f459207f63b8500695dc5f6bd289ce5b6673ea4554f0ef2644f6cd110361a3a81a3adc92229504ebfbbab1118e8050d186183cd38bb8155acf0e0a9fc2acf4aa5a085a315603a9d8a00296a843a9e298890548a681120a78a9024073d69e3e5fa52032f55d152e8196d8049bd3b3572f246d1394752acbc106b9eac7a9a448e931581431973516281853a900f534fa00902d3c25003f656de9c3cfb431f438dbfe1480c8766425586693e46ef8a6237741cf93246dce0ee15534a1f63d6bc93f77798ff00c2819d3bc555de2ad108aed1d569e3f90d684907943838e6976628801191f3521527a55a0198c54c8322ad00fd946daa10518a602d28aa10f1520340878352834843aa456a901fd395fcaa96a5a645a8a6efb930e8f486725736d25b4a629976b0a848ae36accd469a8d9735231940a402d3b771401a08956e2b7ddda80256b361daaf68b18fb43c4f2797bd3e5e3ab0e40a4055d6acfcbb8f307dd939aca294c0d3f0ec822bef2d89025181e9baad6bb01b7bf8ae9782e33f8ad00759e58923575fbac322abc90d3405678aab4b17ca6b444957c9e9414a7162202b934cda7d3356864aa81fa75a70b761d2aae04a13d691d3029a6057e0f149d2b4245a75508514ea621e0d480d202453520a421ea69fee29015afac61d421d9270c3a3775ae42face5b398c728fa1f5acaa2bab9712b536b98b18eb511a43141a434847416f16e35d6f86f427bf9d5540c7f113d85033aebcf065bb47fe8ce777a3d725a9787ae2ca4e51918720d3dc0afa8599b9b3cedc30f985734f0e2901180d1baba70ea7729f7ae9b588bed7a489d07ddc4a07b1a5d40daf0e30bbd12dcff00147989bf0ab12c14d032a490d54962e2ac454311a63474e205768fe5e94ab1e7eb5603c41cf4fc455b8a1343631e61c5559936f4a7160ca72004f4a8ba0f9ab74407d2941ab24753a810e14f1408914d48a690120a70a403fafd6a1bbb58afa1314a3e87d2901c75fd94965398e41f43eb556b924accd90da8a45a8191d2f51480ecf48b469e54555c92702bd4218e1f0c6939e1ae24ebee682998d6fe2c9a2b8259bcc527eeb574b67aa58ead1796d8dc7fe59bd4a7613572a6a1e1d87ca76b6e3fd8eb5e7f7fa515b86502a84664d62cbdab77c31b66b296ce65dc233ff8eb526058f07036f717d632751f38ff00d04d74524348653960aa72c15622934350bc74d08aed153921feed5dc65a860cd5e5b7c2d4365a4579900159d3f1571264519143fd6a0715d48c867d2973d8f5ab10ea78a042d3e810e1520340120352834805a7f5fad202bdf59c77f6e629386fe16f4ae3aeada4b599a29570c3f5ac6a2d2e5c4ac6995cc59130a6d033dc3c11a48d3ad1f52be5118ff9645bd3d6b9ff00136bad7b74e73c7403daa4673a2ece6af5aea4c9de90cea34ef195cc0987c4e3d1cf35d168af6f7b1b248885261e62a75c7ad24da07621d53c2914c0b5a9c1feeb572cba6cba4ea199e374520ab6076ab7a9289bfe3cb5ab6bc23e591bca93f118aea31c5414472439aa52c1544946482aac90d340566869f1c55405e822a965200c549a99b74f599356b1336557fd699fef574232630c7dd6a3c82707ef5682114329c1e57d6a4a621c0d385021e29e2801e0d3c1a404a0d2d201fd7eb55353b04d420c7dd957eeb52038d9e2689ca4836b2f5155cd713361aeb8eb511a407b4f8eb5d445fb0c1f763ebf5af389a72cdd696c5116fa7acb480b11dce2ba3f0feac7fd467a7ce9fd6a59475169e2a92da5f26e7f7a9d8f7c574505dd86af16c56593d50f514d3b12fb993af696a209e28f859e23b773602b8f996aae8fab43a8c00ac80cca3f7a9dd4d12046a8e698f1668029cb6f54e5b7a622a3c34d58f0698d12e7155a692828a133f3555eb6890caedef5195ad91033a74a42ab27d6b4246fdde0fe74bb7be6988404353c5310f14ea007034f06801e0d480d480648a9376464548197ad580bc8bcc8c7ef97f5ae53ee939ea2b1aaba971216e6a23589a1d36a77ad733b3b1eb59c5aa580ddd4bba900e0f5620b968a4574386539a0675170ff006dd27ed50ee2f6ebe6607fcf2cfcd59b06b3242c086e8723daa771dce8ed3c7859043a8c0b750f7e70e3dea8dd69b6f2c8b77e1ed414cea372ae7648bcd527d2427de26968de300b37d875d4fb25d2f1e61e11abb14218546da0c7343915526b7a622949055778aac0ad28c5529698151c55764ad51242cbb85336e2b4111b0e78a695cd59027fbd4854e72b562176d15620e94f148075381a04381a783486480d349d9cd210d67fe215cfebd6401fb4c4383f7c7f5a528de238bd4c334d6ae23634e46a8aa0625266801734edd401afa06a06de7f2ced656cfcadc83c618550bd8cda5cbc59240fbac7f887ad08087cca413105581c153907d0d303761d760d4225b5d7537a8fb974a3f7895a9637faa785516481d753d14f4c1e16a2dd07b1df685aed86b706fb297247df89b874ad43186a9432acb6f5465b7ad04509e1aa12c54c453923aaec98ab11132e6a1718ad5088f6d308ab24637d29a38fbbd2b410eebd28ab244a280141a75002d381a043c3529348080b6c3ed4d7c11b5b956ab24e6352b3fb1cfc7fab6fbb548d704d599d08be699589425253012973400a1f6e083822aedd49f6bb5497f8e3ebf4a4050cd26698066b4348d6eef48909b76cc6df7e26fbad49a0372da1b4d4a55bdf0fce74fd523f9becdbb6fd6ba9f0ff008f0c737d83c491fd96e578f3f6e14d43d7529763bc4d93461d08656190477a826b6a6988cdb8b6f6acd9adeac451960aa72455422b3c75095f5ab422164c74a88f35a884db5195ee2ac91bd7d8d2e7b1ab420a4aa1094a0d003a9734085dd46ea0431f91502b7f0b55a1105f41f6a80c67ef0e54d733229462a7a8ae6c42ea6b0372fa0b7c09eccb796dc346fd636f4aa38ae366a34d36801292801b4f864319f63400d6eb4da0028a0072394656425594e411d4575169e21b3d4a25b3f1247bd47dcbc41f3c749f743dcd5b4b9d63c1444ba7ceba9e88df300a7e5c57a0f877c53a6f88a2ff0045936ce065e07e1c5479a2b734e6b70d59d716bed544199716d59f3415422949155578eac0819715132035a2110ed60704530a735a122141518e78ebef5620e9d7a52d5923692a80334b4803346ea621bbaa3939aa10c0d9fa8acad66dfa4e83d9ab3a8af12a3b9a97bf66fb3a476e920933994b74f61598c95e71b90b2d331400d34d3400da4a005a6d00149400a28a0669e91ad5e690ff00e8d27eec9cb44df75ab760874fd6984fa449fd9da9a7cc21dd8e696de81e6751a178f6e6c66163e2685948ff009780b5df46f0ddc2b2c1224b1bfdd74390696c53d752a5cdad64cf6d54419d341546586a8454923a81a3ab422a4d32a3629386e95698863267ad262b410d22a3e9d2ac90ebd292ac4369334c0334dcd02133466a8444df29cd35f0c0a9fbad4c0dcd5f4692da56565c115832c18af2a5b9d25574a8196901191519a006d262800a434009450029a41400ea507078a00e96c7c4b1dcc62d75e8fed317f0dc01fbc4adcb39350d017edda0ce2eac1be6641c83447f91957b1d9f86fc67a778802c27fd1af0ff00cb173f7ab667b5cd2134655c5b566cf6f4c9284d16deb59d70bbb807155703365b63e950ff00ab5e3ad0b418f8e657a7915d29998c22a23fad58861fd69339fad588434c35421b9a4cd0026693354210d30d311ed7a969d6fac5b0752a5b1f238af3ed634392da460c9835e52d51d0739736a57b55178a90caee95030a00653680173d8d211e9400da51400da5a0028a005abba66ab77a5cde65a4c53fbcbfc2d435703a18df4bf12771a76a6dff007ee535b9a5f8cf56f0f4eb67e2085ee6dfa097397a5bfa8d763bdb2bcb1d6ad45c584e93467d3a8aaf73684534268c7b8b6f5acd9ada811425848354e55fef0cd00557854f2a769a40ed1f120fc6b58889321ba546cbcd741046d4caa01b9f5a61ab42186999a620cd266800cd35a988ee3c37e2292c1f07e7818fcc9fd6bba9a2b4d66d032b0753f75c76af2d6874b387d7fc3f25bb1f978ec45727736c5339154233258eab32d481115a66280131498a006e28340094500145300a2801d5bda6f89648a1fb26a518beb23c10ff007d4526069db5acb6f27f6a784afa43b7efc59f9d7fd9aeb3c3ff00102d6ff16daca2d95d671e6748c9a5fde43df43a6b9b60c322b1ee6d714c9336683d45509ad8530284f6c7d2a93064a62230e07fb352673d6b78b258c34dad4444f5096aa0184d349aa10dcd19a4019a4cd324b96f7056ba6f0ff8866d3e5ca9dca7ef21e86bcd6749e896b7569ac5a6e4c3a1eaa7aad72de23f0d15dd2c0b94fe54e22670b7b62d1b1c8acc921a605774a84ad480dc537140098a662800a4a00292980b49400b45004b6b75359ce26b695a2907f129ae8a3d574dd6d447ad2fd9eeb0156ee21d696da81a567a9eb7e0e0b8617da4ff0008eb1e2bb6d175ed33c451ff00a249b6e31f35bc9c38a36f40dc9aeacfdab22e2df154499d3458aa52c79ea280284d00ed55b6321eb8154804594138a971c56ea5724af275aaed5a011e69334c91a6933400669334c42c7255c866c579c741bba46af359ceb2c526d61fe715e89a1f8820d55046f88ee71caf66a5b0f72b6b7e198aed4bdb2857feed79fea7a4496cec19704569b9062cd6e476aaaf1548c84a546568018c29b8a40371498a004a4a601450014500251401a7a56b979a5fc90bee80f585f9535a715bd86aee24d29ffb3f500432c0c70bba96c1e68e874cf1adf69930b1f12db48c3b4e3ef8aeae392d752b6fb4594c93c47f89685a680f5d5142e6d6b32783daa89284d0d509a1aa1154c0de94f0b220e7a55446432d556ae8208cd3334009494c419a42681102b5598e4ae03a0b714d5a5677ad1b021b06819de683e2e0c161d40fd25ae86fb4fb4d560c9da770f9655a13b09a385d77c2f2da12c06e8ffbc2b97b9b3287a568499f24355d92a464252936d210c2b4dc500331498a061494005250025140051401bf63e256317d97588bedf6b9fe2ff58b57aded2e6d58ea3e16be6953f8e3fe35f6a5fdd62db537f48f1a5ade7fa3eaa82cee41c6ff00f9666b6e7b70c370c107a114d7660d19b35b0f4aa5243ed5a125768eaace2ad019b3d53635a088c9a6e69884a4a042669a5a9815c1a954d709b93a3d5b8a4a00bf04f8ae9742f10cfa71c2fcd11ea86819de69faa59eab19119e7f8a27eb595ac78561b805ed7e56fee538c8968e1b52d1a4b7728e9b48ac6b8b42bdaad88a4d154463a4034a54456900c2b4ddb4804c53714009498a061494c029290054d6b7335a4c26b695e2907f121c50c0dc1ab58eaff2eb51f9571daf211572de6d63c31187b675bdd2ce48dbf3c78f5a37d18b63a2d33c4161ac2aaa9f22e0ff00cb273566783daad3114658aa85cae055a11897279aa4cd5a08849a6e6800dd464d310da61a00841a954d719a9329a991a828b31c957a09a981a56d78d1b2b0382bc83e95d9e8fe2ece23be191ff3d57ad2607472c169a9403704993b30ae5758f08b72f6a3cc4f4ee2ae2fa19b472177a5bc6c415acc96d0af6aa02b3435098aa464663a88c7400ddb4ddb4806eda6e290c4c518a004a4a60252521055fd2f57bcd29f75a4c54139643cab51619ad9d235a5e31a5df1edff002c64ab906abab688cb0ea5199a0e8a49a6b5f51791b96f7f69a8affa34993fdc3c30aa5a97c8a6b4892ce66e4f354dab410ca4a402669334c42134d268022a7ad729a9329a956828990d588db14c0b71cb57619a811b3a56b571632031498f51d8d767a5788edef06db8db0c9eb9f94d21ee5ebed2ed6fc1f353e6fef8eb5ca6abe14963cb423cd4f6eb5a4657d0cce66e74b29d4567cb624550155ed88aaed0d481118aa231d218c294d29480615a6e2801b8a6e2801292800a5028024515d1f876e6eb8b3e27b67f97c99795a00e93c45e06fb0797369d70aaecdf2c64e3e6ae4eeafaf6190dbdf2b0917fbdd6afcc9f233a49b75405e9dc6377d233e3ad3e610c328a4f3462a7982c33cda4cb9e82a79863c538541448b53a5032655a945051229ab31c94c0b29355c82e8af7a649bba4f8867b20151b31ff0070f4aeb34df105adeafef31049e85b8a9b0f72ddee976b7a0f9b1fcdfde1d6b9bbff000ac8a49831227eb5a465dccce7ae749652415c567cda7fb55014a4d68aab2394cbb8f03396fdd49115f539154bfe10bbc47e2207fe042af9a2c474b3e3c35e1b6f280f380fcdcd792dfcbbe426a11466c9559a90111a61a40329298094500145311fffd9b2c55592d88a4057686a3315202268ea264a43232b4dc500371498a402629e05004d1af35defc3dd2c5c6a11c8ebf245fbcfcba5302dfc4cd4165ba4b45ff9771cff00bc79af3ebbb89ae1b334ad237ab9c9a00a0f511a4032928012968024822699f6a0c9ab99da305196a64345614f0280278e3cd5eb7b7cf5a65a45d4b4c9e29d359b463a531950a629338a043d5f153a4f4124e97156a1bc2a7ad3037749d7e7b201627f93fb87eed759a7788edeeb89c792ff005c8a9683734de1b6bc50cca9282386ac9bcf0dc4fcc2d8f63551911639ebed06687ef4758d71a7b0ed56233e4b2f6aab25afb5302b3c155da1a432068e99b2a40694a615a43136d2aad022ddac5b9c0af5ef045a8b0d1a5ba9b08afce7fd95a18cf38f10de9bcbf9e63d647dd5832d531155ea13505094da621296803674883cb88ca7ab74ab77d6c1611229e7f885677d4661ad4e8053197ad62dc7ad6ed969cd2e00c53344765a3784f7a07b82156abebda17d8d4b9dbb09e2a90ba9c35f2ed908aa25a8131375383d210f592a65968116a1b8ad082f36f7aa03634fd6a6b73fbb94ad74965e2756c09d3fe04b50e206dc1796d743f7722b67f87bd4573a55a5c0e63da7fd9a14ac4b461de78598e7c92ac3f5ac2bbd0e68bef44c3f0ad96a41953e9ec3f86a84d678ed4c65192d88ed503434864463a8cc75203365284a00d9d0acdae2ea34419662157eb5e95e34bafeccf0fadac071e6623ebfc03ad2ea33c92e5f731aa5250c0aed511a918d34da64853e1dbe60ddd290cd9f9604dee71e959d737ad2e42fca95290ee305588e819a16884b574fa53846141aa3b7d3f5e862804653e55e9cd64f8935c59c6d1ca7a35111b4b7386bfb85918fc8056548ca4f4aa3322dc28dd4123f753c3d00489262acc53d302e453d5c8ae88aa11720d4597bd6dd9789ae22eb26ff00f7f9a9682e6dda789e0900132107d56b5a3bbb6b81859637dddb351b0588a7d26ce71cc217dd78ac7bbf09a3f30c83e8456aaa7726c615ef852ee3e90eeff779ac2b9d1e442414e6b5dc9284ba7b8fe1aaaf6ac3b52190b407d28480e6a467a0fc3cd2c79af78c3fd570bf53591e3dd51eef56963cfee61fdda63f5350b719c5c9559e90103530d218ca4a62128a04145302daaf353a5666a8bd6cd835ab6ccdd4549aa2c5cea4635099ace9afbcc4e6a90999d2cb55d9aa8c99193499a091c1a9e1e80143d4a925032ca4953acf5404e93d4c9715422ca5d11deadc7a8b2ff152034ad3c457502ed498e3d3d2b5adfc5f20ff005b123fe952e206a5b789ec66fbfbe23ee322afadc58ea08177c3303cec6a87ee8f96fb114da269f36775ba8fa7159b71e0fb2907eedd90fb8c")) );
    }
}
